import React, { Component } from 'react'
import { Row, Col, Switch, InputNumber } from "antd"
export default class index extends Component {
  constructor(props) {
    super(props)
    this.state = {
      isMock: false,
      mockCount: "0",
    }
  }
  triggerChange(changedValue) {
    if (this.props.onChange) {
      this.props.onChange({
        ...this.state,
        ...this.props.value,
        ...changedValue,
      });
    }
  }
  render() {
    const myIsMock = typeof this.props.value == "undefined" ? this.state.isMock : this.props.value.isMock;
    return (
      <Row gutter={[24, 0]}>
        <Col style={{ paddingTop: 3 }}>
          <Switch
            checked={typeof this.props.value == "undefined" ? this.state.isMock : this.props.value.isMock}
            onChange={(checked) => {
              this.setState({
                isMock: checked,
              });
              this.triggerChange({ isMock: checked })
            }}
            checkedChildren="是"
            unCheckedChildren="否"
          />
        </Col>

        {!myIsMock ? null :
          <Col>
            <span>模拟数据条数：</span>
            <InputNumber
              value={typeof this.props.value == "undefined" ? this.state.mockCount : this.props.value.mockCount}
              onChange={(v) => {
                this.setState({ mockCount: v })
                this.triggerChange({ mockCount: v })
              }}
              precision={0}
              step={10}
              min={0}
              max={99999}
              maxLength={5}
            />
          </Col>
        }

      </Row>
    )
  }
}
